﻿import pygame
from pygame.locals import *

import Properties
from Primitives import *
from Entities import *
from Units import Snake

def InitialScene():
	backSurface = pygame.Surface( (400,400) )
	backSurface = backSurface.convert()
	backSurface.fill((255, 255, 255))
	
	objects = []
	
	esquerdo(objects)
	#direito(objects)
	
	class EventManager(Primitives.EventManager):
	
		def fireEvent(self, scene, event ):
			if event.type == QUIT:
				#pass
				scene.Snake.imprimir()
			elif event.type == KEYDOWN and event.key == K_RETURN:		
				scene.Snake.flag_minimizar = True
				scene.Snake.restart()				
				#scene.Snake.unit.iteracao = 0
			elif event.type == KEYDOWN and event.key == K_SPACE:		
				scene.Snake.flag_minimizar = False
				
			elif event.type == MOUSEBUTTONDOWN:
				scene.Curve.goDraw();
			elif event.type == MOUSEBUTTONUP:
				scene.Curve.stopDraw()	
				scene.Snake.set_curva( scene.Curve )
				#scene.Curve.curva.imprimir()
			elif event.type == KEYDOWN and event.key == K_s:
				scene.Snake.unit.comp_suavidade_flag = not scene.Snake.unit.comp_suavidade_flag
			elif  event.type == KEYDOWN and event.key == K_c:
				scene.Snake.unit.comp_continuidade_flag = not scene.Snake.unit.comp_continuidade_flag
			elif  event.type == KEYDOWN and event.key == K_x:
				scene.Snake.unit.comp_cor_flag = not scene.Snake.unit.comp_cor_flag				
			elif  event.type == KEYDOWN and event.key == K_BACKSPACE:
				scene.Snake.unit.go_back(-1)	
				scene.Snake.update_flag = True
				'''
			elif  event.type == KEYDOWN and event.key == K_q:				
				scene.Snake.setar_quina()
				'''
			elif  event.type == KEYDOWN and event.key == K_a:				
				scene.Snake.setar_alfa_especial()								
			elif  event.type == KEYDOWN and event.key == K_b:				
				scene.Snake.setar_beta_especial()				
			elif  event.type == KEYDOWN and event.key == K_g:				
				scene.Snake.setar_gama_especial()												
			elif  event.type == KEYDOWN and event.key == K_e:					
				scene.Snake.setar_espalhamento()															
			elif  event.type == KEYDOWN and event.key == K_p:				
				scene.Snake.unit.modo = (scene.Snake.unit.modo+1)%2	
			elif  event.type == KEYDOWN and event.key == K_t:				
				scene.Snake.setar_forca_central()												
			elif  event.type == KEYDOWN and event.key == K_f:				
				print scene.Snake.unit.calcular_funcional( scene.Snake.unit.xk ).normal()
			elif  event.type == KEYDOWN and  event.key == K_PERIOD:
				scene.Snake.str_indice += "."
			elif  event.type == KEYDOWN and	 event.key == K_COMMA:							
				scene.Snake.str_indice += ","
			elif  event.type == KEYDOWN and	 event.key == K_MINUS:							
				scene.Snake.str_indice += "-"				
			elif  event.type == KEYDOWN: #Numero
				scene.Snake.str_indice += str(event.key-48)
	
	initialScene = Scene(EventManager(),backSurface,objects)
	return initialScene
	
def esquerdo(objects):
	textRect = pygame.Rect( (20,20), (200,30) )
	#textRect.centerx = backSurface.get_rect().centerx
	textColor = (0,0,0)
	font = pygame.font.Font(None,24)
	text = font.render( "Desenhe uma curva inicial", 1, textColor )
	
	textSpr = GameObject("Title")
	textSpr.image = text
	textSpr.rect = textRect
	
	curva = CurveEntitie("Curve")
	#curva.rect.centerx = backSurface.get_rect().centerx
	curva.rect.y = 60

	snake = SnakeEntitie("Snake")
	snake.set_curva( curva )
	snake._is_visible = False	
	
	objects.append( textSpr )
	objects.append( curva )
	objects.append( snake )	
	
def direito(objects):
	pass
	